package com.leetcode.LC;

public class LC415 {
    public String addStrings(String num1, String num2) {
        StringBuilder res = new StringBuilder("");
        int a = num1.length() - 1, b = num2.length() - 1, carry = 0;

        while (a >= 0 || b >= 0) {

            int n1 = a >= 0 ? num1.charAt(a) - '0' : 0;
            int n2 = b >= 0 ? num2.charAt(b) - '0' : 0;
            int tmp = n1 + n2 + carry;
            carry = tmp / 10;
            res.append(tmp % 10);
            a--;
            b--;
        }
        if (carry==1){
            res.append(1);
        }

        return res.reverse().toString();
    }

    public static void main(String[] args) {
        System.out.println(new LC415().addStrings("8", "7"));
    }
}
